Skip to content

Android: keep direction_* drawables from resource shrinking#945

Open
freszu wants to merge 1 commit into
stadiamaps:mainfrom
freszu:android-keep-maneuver-drawables
Open

Android: keep direction_* drawables from resource shrinking#945
freszu wants to merge 1 commit into
stadiamaps:mainfrom
freszu:android-keep-maneuver-drawables

Conversation

@freszu

@freszu freszu commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Note! it looks like it starts happening when switching to AGP 9
before there was a heuristic checking for that - with AGP 9 and default settings this looks to be gone

ManeuverIcon looks up the direction_* drawables by name via Resources.getIdentifier, so the AGP resource shrinker sees no static reference to them and strips all 95 icons from any consumer app built with isShrinkResources = true. Because ManeuverImage deliberately ignores resolution failures, the symptom is maneuver icons silently missing in release builds only.

This ships a tools:keep rule inside the ui-shared AAR. Keep files in library resources are merged into the consuming app and honored by the resource shrinker, so consumers get the fix transparently.

The file is named ferrostar_ui_shared_keep.xml rather than the conventional keep.xml to avoid a resource-merge collision with a consumer's (or another library's) own res/raw/keep.xml; the shrinker scans all raw XML resources for tools:keep attributes regardless of file name.

Verified in a consumer app (AGP 9.x, isMinifyEnabled = true, isShrinkResources = true): before, build/outputs/mapping/<variant>/resources.txt listed every drawable:direction_* as removed; with the rule merged, all 95 report reachable from keep xml file and the icons render.

ManeuverIcon resolves the direction_* drawables at runtime via
Resources.getIdentifier, which the AGP resource shrinker cannot trace.
Ship a tools:keep rule in the ui-shared AAR so the icons survive
consumer builds with shrinkResources enabled.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@freszu

freszu commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

format lint will fail - its broken on main - in #944 i've fixed it

won't be touching this in that PR - its pure android change

@freszu
freszu marked this pull request as ready for review July 23, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant